package com.gyms.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.gyms.R;
import com.classic.okhttp.beans.HVVenueWeekTimesBean;

import java.util.List;

import utils.DateUtil;

/**
 * ltx on 2016/11/22 13:09
 * 订座的tabAdapter
 */
public class SeatTabAdapter extends BaseAdapter {

    private Context context;
    private List<HVVenueWeekTimesBean> mHVVenueWeekTimesBeanList;//日期的bean
    private int selection=0;//选中的pos

    public SeatTabAdapter(Context context) {
        this.context = context;
    }

    public void setSelection(int selection){
        this.selection = selection;
    }

    @Override
    public int getCount() {
        return null==mHVVenueWeekTimesBeanList?0:mHVVenueWeekTimesBeanList.size();
    }

    @Override
    public Object getItem(int pos) {
        return mHVVenueWeekTimesBeanList.get(pos);
    }

    @Override
    public long getItemId(int pos) {
        return pos;
    }

    @Override
    public View getView(int pos, View view, ViewGroup viewGroup) {
        ViewHolder vh;
        if (view == null) {
            view = LayoutInflater.from(context).inflate(R.layout.item_seat_tab, viewGroup,false);
            vh = new ViewHolder();
            vh.mTvDay = (TextView) view.findViewById(R.id.tv_tab_seat_day);
            vh.mTvWeek = (TextView) view.findViewById(R.id.tv_tab_seat_week);
            vh.viewBottom = view.findViewById(R.id.view_bottom);
            vh.mTabLayout= (LinearLayout) view.findViewById(R.id.ll_tab_layout);
            view.setTag(vh);
        } else {
            vh = (ViewHolder) view.getTag();
        }
        HVVenueWeekTimesBean mHVVenueWeekTimesBean=mHVVenueWeekTimesBeanList.get(pos);
        boolean isBook=mHVVenueWeekTimesBean.getIsBook();//是否可预订
        long dt = mHVVenueWeekTimesBean.getVenueTime();//转化为毫秒的时间戳
        long dateTime = dt * 1000;
        String mDateS = DateUtil.stampToDate(dateTime);
        String mWeek = DateUtil.getWeek(dateTime);
        vh.mTvDay.setText(mDateS);
        vh.mTvWeek.setText(mWeek);
        if(isBook){//可预订可点击
            vh.mTvWeek.setTextColor(context.getResources().getColor(R.color.c_666666));
            vh.mTvDay.setTextColor(context.getResources().getColor(R.color.c_666666));
        }else{//不可预订 设置不同的颜色 不可点击
            vh.mTvWeek.setTextColor(context.getResources().getColor(R.color.c_DDDDDD));
            vh.mTvDay.setTextColor(context.getResources().getColor(R.color.c_DDDDDD));
        }
        if (pos == selection) {
            vh.viewBottom.setVisibility(View.VISIBLE);
            vh.mTvWeek.setTextColor(context.getResources().getColor(R.color.c_0396EB));
            vh.mTvDay.setTextColor(context.getResources().getColor(R.color.c_0396EB));
        } else {
            vh.viewBottom.setVisibility(View.INVISIBLE);
            /*vh.mTvWeek.setTextColor(0xff555555);
            vh.mTvDay.setTextColor(0xff555555);*/
        }
        return view;
    }

    public void setHVVenueWeekTimesBeanList(List<HVVenueWeekTimesBean> HVVenueWeekTimesBeanList) {
        mHVVenueWeekTimesBeanList = HVVenueWeekTimesBeanList;
    }

    class ViewHolder {
        TextView mTvWeek;
        TextView mTvDay;
        View viewBottom;
        LinearLayout mTabLayout;
    }

}
